home *** CD-ROM | disk | FTP | other *** search
/ Aminet 34 / Aminet 34 (2000)(Schatztruhe)[!][Dec 1999].iso / Aminet / util / mouse / FreeMouse.lha / FreeMouse / Cx.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-02  |  2.9 KB  |  160 lines

  1.  
  2. #include <exec/types.h>
  3. #include <exec/ports.h>
  4. #include <exec/memory.h>
  5. #include <libraries/commodities.h>
  6. #include <clib/exec_protos.h>
  7. #include <clib/commodities_protos.h>
  8. #include <clib/alib_protos.h>
  9.  
  10. #include "Icon.h"
  11. #include "GUI.h"
  12. #include "CxCustom.h"
  13.  
  14. #include "Cx.h"
  15.  
  16. void *CxBase;
  17.  
  18. BOOL HandleCxMessages(struct CxContext *cx,unsigned long signals)
  19. {
  20.   struct Message *msg;
  21.   struct GUIContext *gui=cx->UserData;
  22.   long id;
  23.   BOOL result=TRUE;
  24.   if(cx)
  25.   {
  26.     if(signals&cx->Signals)
  27.     {
  28.       while(msg=GetMsg(cx->Port))
  29.       {
  30.         id=CxMsgID((CxMsg *)msg);
  31.         ReplyMsg(msg);
  32.         switch(id)
  33.         {
  34.           case CXCMD_DISABLE:
  35.             ActivateCxObj(cx->CustomObject,FALSE);
  36.             break;
  37.           case CXCMD_ENABLE:
  38.             ActivateCxObj(cx->CustomObject,TRUE);
  39.             break;
  40.           case CXCMD_UNIQUE:
  41.           case CXCMD_APPEAR:
  42.             gui->Show(gui);
  43.             break;
  44.           case CXCMD_DISAPPEAR:
  45.             gui->Hide(gui);
  46.             break;
  47.           case CXCMD_KILL:
  48.             result=FALSE;
  49.             break;
  50.         }
  51.       }
  52.     }
  53.   }
  54.   return(result);
  55. }
  56.  
  57.  
  58. BOOL Commodities_Setup()
  59. {
  60.   if(!(CxBase=OpenLibrary("commodities.library",37)))
  61.     return(FALSE);
  62.   return(TRUE);
  63. }
  64.  
  65.  
  66. void Commodities_Cleanup()
  67. {
  68.   if(CxBase)
  69.   {
  70.     CloseLibrary(CxBase);
  71.     CxBase=NULL;
  72.   }
  73. }
  74.  
  75.  
  76. struct CxContext *CreateCxContext(void *userdata)
  77. {
  78.   struct CxContext *cx;
  79.   char *hotkeystring;
  80.   CxObj *hotkeyobj;
  81.  
  82.   struct NewBroker MyNewBroker =
  83.   {
  84.     NB_VERSION,
  85.     "FreeMouse",
  86.     "Fine-tune your mouse - V1.0",
  87.     "© 1998 - Black Five SoftDesign",
  88.     NBU_UNIQUE|NBU_NOTIFY,
  89.     COF_SHOW_HIDE,
  90.     127,
  91.     NULL
  92.   };
  93.  
  94.   if(!(cx=AllocVec(sizeof(struct CxContext),MEMF_CLEAR)))
  95.     return(NULL);
  96.  
  97.   cx->Dispose=DisposeCxContext;
  98.   cx->UserData=userdata;
  99.   cx->Handle=HandleCxMessages;
  100.  
  101.   cx->MouseSpeed=(GetNumericToolType("Speed",100));
  102.   cx->MMBShift=MatchToolType("MMBShift","Yes");
  103.   cx->ClickToFront=MatchToolType("ClickToFront","Yes");
  104.   if(!(cx->Port=CreateMsgPort()))
  105.   {
  106.     cx->Dispose(cx);
  107.     return(NULL);
  108.   }
  109.  
  110.   cx->Signals=(1<<cx->Port->mp_SigBit);
  111.  
  112.   MyNewBroker.nb_Port=cx->Port;
  113.   if(!(cx->Broker=CxBroker(&MyNewBroker,NULL)))
  114.   {
  115.     cx->Dispose(cx);
  116.     return(NULL);
  117.   }
  118.  
  119.   if(hotkeystring=GetStringToolType("CX_POPKEY"))
  120.   {
  121.     if(!(hotkeyobj=HotKey(hotkeystring,cx->Port,CXCMD_APPEAR)))
  122.     {
  123.       cx->Dispose(cx);
  124.       return(NULL);
  125.     }
  126.     AttachCxObj(cx->Broker,hotkeyobj);
  127.   }
  128.  
  129.   if(!(cx->CustomObject=CxCustom(&CxCustomRoutine,0)))
  130.   {
  131.     cx->Dispose(cx);
  132.     return(NULL);
  133.   }
  134.   AttachCxObj(cx->Broker,cx->CustomObject);
  135.  
  136.   ActivateCxObj(cx->Broker,TRUE);
  137.  
  138.   return(cx);
  139. }
  140.  
  141.  
  142. void DisposeCxContext(struct CxContext *cx)
  143. {
  144.   if(cx)
  145.   {
  146.     if(cx->Broker)
  147.     {
  148.       DeleteCxObjAll(cx->Broker);
  149.       cx->Broker=NULL;
  150.     }
  151.     if(cx->Port)
  152.     {
  153.       DeleteMsgPort(cx->Port);
  154.       cx->Port=NULL;
  155.     }
  156.     FreeVec(cx);
  157.   }
  158. }
  159.  
  160.